#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

int main()
{
   // int fd = open("log.txt",O_RDONLY);
   // dup2(fd,0);
   // char buff[100000];
   // ssize_t n = read(0,buff,sizeof(buff));
   // if(n > 0)
   // {
   //     buff[n] = 0;
   //     printf("redir buff:%s\n",buff);
   // }



   // int fd = open("log.txt",O_WRONLY | O_CREAT | O_APPEND);
   // dup2(fd,1);
   // const char* ms = "fwrite\n";
   // fwrite(ms,1,strlen(ms),stdout);
   // write(1,"write\n",6);
   // fputs("fputs\n",stdout);
   // fprintf(stdout,"snprintf:%d\n",fd);
   // printf("printf:%d\n",fd);
   





    close(1);
    int fd1 = open("log.txt",O_WRONLY | O_TRUNC | O_CREAT,0666);
    //write(fd1,"write\n",6);
    printf("%d\n",fd1);
    //fprintf(stdout,"%s","fprintf\n");
    //fflush(stdout);
    close(fd1);
    //fclose(stdout);

    //printf("stdin:%d\n",stdin->_fileno);
    //printf("stdcout:%d\n",stdout->_fileno);
    //printf("stderr:%d\n",stderr->_fileno);

    //FILE* fp = fopen("log.txt","w");
    //printf("fp:%d\n",fp->_fileno);
    //char buff[128];
    //ssize_t n = read(0,buff,sizeof(buff));
    //if(n > 0)
    //{
    //    buff[n - 1] = 0;
    //    printf("%s\n",buff);
    //}
    // umask(0);
    //int fd = open("log.txt",O_WRONLY | O_CREAT | O_TRUNC , 0666);
    ///int fd = open("log.txt",O_WRONLY | O_CREAT | O_APPEND , 0666);
    ///if(fd < 0)
    ///{
    ///    perror("open fail");
    ///    exit(1);
    ///}

    ///printf("%d\n",fd);

    ///const char* message = "sssss\n";
    ///// write(fd,message,strlen(message));
    ///close(fd);

    return 0;
}
